package com.rasou;

import com.rasou.jms.Constant;
import com.rasou.jms.JmsReceiveListener;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DistributedEventSubscriber {
    private final ExecutorService executorService  = Executors.newSingleThreadExecutor();

    private Runnable listenRemoteThenSendLocalMsg;

    public DistributedEventSubscriber( Runnable listenRemoteThenSendLocalMsg ) {
        this.listenRemoteThenSendLocalMsg = listenRemoteThenSendLocalMsg;
    }

    public void start() {
        executorService.execute( listenRemoteThenSendLocalMsg );
    }


    public static void main( String[] args ) {
       DistributedEventSubscriber eventSubscriber = getJMSDistributedEventSubscriber();

        eventSubscriber.start();
    }


    private static DistributedEventSubscriber getJMSDistributedEventSubscriber() {
        DistributedEventSubscriber eventSubscriber = new DistributedEventSubscriber(
                new JmsReceiveListener( Constant.URL, new LocalMsgFromRemoteListener() )
        );
        return eventSubscriber;
    }
}
